home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / rigctrl / catcntrl / catcom1.c next >
Encoding:
C/C++ Source or Header  |  1996-03-31  |  51.5 KB  |  2,529 lines

  1. /*12/16/95 Eugene L. Langberg WA3AKK*/
  2. /*YAESU FT-767GX CAT (Computer Aided Tuning or Transceive) PROGRAM*/
  3. /*Program expanded to include additional memories on disk*/
  4. /*This version is patched to operate through com1*/
  5. /*The changes are made in initcom(), comin(), comout() and testport().*/
  6. /*The value of FACTOR is also changed to reflect the speed of the cpu.*/ 
  7. /*when tested on a 286 machine.*/ 
  8.  
  9. #include <stdio.h>
  10. #include <conio.h>
  11. #include <bios.h>
  12. #include <graph.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. #include <process.h>
  17. #define ESC 27
  18. #define clrscr() system("cls")
  19. #define CLRSCR printf("%c[2J",ESC)
  20. #define FALSE 0
  21. #define TRUE 1
  22. #define CLREOL printf("%c[K",ESC)
  23. #define EDTB "\0"
  24. #define BACKSPACE printf("\010")
  25. #define PAD 2
  26. #define FACTOR 0
  27. #define TIMEOUT 18000
  28. #define MAXGENERAL 100
  29. #define MAXREPEATER 25
  30.  
  31. void examine_files(int num);
  32. void disk_memory_control(void);
  33. int selection(int choice);
  34. int add_station(int num);
  35. int delete_station(int num);
  36. int getreply(void);
  37. void backup(int spaces);
  38. int gen_insert(int rcnt , int num);
  39. int loadfile(int num);
  40. int rep_insert(int rcnt , int num);
  41. int savedata(int maxcnt, int num);
  42. void input_data(int num);
  43. void remove_record(int del , int cnt , int num);
  44. void reindex(int cnt , int num , int j);
  45. void viewfile(int cnt , int num);
  46. void press_enter(int x, int y);
  47. char *convert(char *buff , char *freq);
  48. void recall(int num);
  49. void do_it(char *func);
  50. void store(int num);
  51. char *hertz(char *buffer, int k);
  52. void vfo_mode(int m);
  53. void get_data(int num);
  54. void pl_tone(int b);
  55. void edit_control(void);
  56. char edit_selection(char opt);
  57. void edit_records(int num);
  58. void edit_station_record(int rec, int num);
  59.  
  60. struct general
  61. {
  62.     char rec[3 + PAD];
  63.     char freq[8 + PAD];
  64.     char mode[3 + PAD];
  65.     char call[8 + PAD];
  66.     char loc[34 + PAD];
  67. };
  68. struct general g[MAXGENERAL];
  69. struct general gentemp,*ptg1,*ptg2;
  70.  
  71. struct repeater
  72. {
  73.     char rec[3 + PAD];
  74.     char afreq[8 + PAD];
  75.     char bfreq[8 + PAD];
  76.     char mode[3 + PAD];
  77.     char tone[6 +  PAD];
  78.     char call[8 + PAD];
  79.     char loc[34 + PAD];
  80. };
  81. struct repeater r[MAXREPEATER];
  82. struct repeater reptemp,*ptr1,*ptr2;
  83.  
  84. char cmd[10],modifier[15],binary[8];
  85. char *lstr[] = { "67.0","71.9","77.0","82.5","88.5","94.8","100.0","103.5",
  86.          "107.2","110.9","114.8","118.8","123.0","127.3","131.8",
  87.          "136.5","141.3","146.2","151.4","156.7","162.2","167.9",
  88.          "173.8","179.9","186.2","192.8","203.5","210.7","218.1",
  89.          "225.7","233.6","241.8","250.3",EDTB };
  90.  
  91. char *hstr[] = { "67.0","71.9","74.7","77.0","79.7","82.5","85.4","88.5",
  92.          "91.5",EDTB };
  93.  
  94. char **ptr;
  95. int status[90],bytcnt,clear;
  96. int catflag,endprog;
  97. int xmiterror;
  98.  
  99. parse(chptr)
  100. char *chptr;
  101. {
  102. char *mod;
  103. int k;
  104. for(k=0;k<=15;k++)
  105.     modifier[k] = 0;
  106. mod = modifier;
  107. k = 0;
  108. while((*chptr != 0) && (*chptr != ' '))
  109.     {
  110.     *chptr++;
  111.     k++;
  112.     }
  113. if(*chptr == ' ')
  114.     {
  115.     *chptr++;
  116.     while(*chptr != 0)
  117.     *mod++ = *chptr++;
  118.     }
  119.     return(k);
  120. }       /*end of parse*/
  121.  
  122. void match(func,cnt)
  123. char *func;
  124. int cnt;
  125. {
  126. char *up,*dn,*cat,*band,*split,*clar,*mtov,*vtom,*swap,*prog;
  127. char *freq,*vfo,*mem,*mode,*ham,*tone,*check,*aclr,*quit;
  128. char *on,*off,*gen,*a,*b,*mr,*lsb,*usb,*cw,*am,*fm,*fsk;
  129. char *hiq,*loq,*m0,*m1,*m2,*m3,*m4,*m5,*m6,*m7,*m8,*m9;
  130. char *help;
  131.  
  132. up = "up"; dn= "dn"; cat= "cat"; off = "off"; on = "on"; band = "band";
  133. split = "split"; clar = "clar"; mtov = "mtov"; vtom = "vtom"; swap = "swap";
  134. prog = "prog";hiq = "hiq";loq = "loq"; freq = "freq";
  135. vfo = "vfo"; a = "a"; b = "b"; mr = "mr"; mem = "mem"; m0 = "0";
  136. m1 = "1"; m2 = "2"; m3 = "3"; m4 = "4"; m5 = "5"; m6 = "6"; m7 = "7";
  137. m8 = "8"; m9 = "9"; mode = "mode"; lsb = "lsb"; usb = "usb"; cw = "cw";
  138. am = "am"; fm = "fm"; fsk = "fsk"; ham = "ham"; gen = "gen";
  139. tone = "tone"; check = "check"; aclr = "aclr"; quit = "quit"; help = "help";
  140.  
  141. if((strncmp(func,up,cnt) == 0) && (cnt == 2))
  142.     {
  143.     bytcnt = 5;
  144.     cmd[4] = 0x2;
  145.     return;
  146.     }
  147. else
  148. if((strncmp(func,dn,cnt) == 0) && (cnt == 2))
  149.     {
  150.     bytcnt = 5;
  151.     cmd[4] = 0x3;
  152.     return; 
  153.     }
  154. else
  155. if((strncmp(func,cat,cnt) == 0) && (cnt == 3))
  156.     {
  157.     bytcnt = 86;
  158.     cmd[4] = 0x0;
  159.     if(strcmp(modifier,on) == 0)
  160.         {
  161.         cmd[3] = 0x0;
  162.         catflag = TRUE;
  163.         }
  164.     else
  165.     if(strcmp(modifier,off) == 0)
  166.         {
  167.         cmd[3] = 0x1;
  168.         catflag = FALSE;
  169.         }
  170.     else
  171.         {
  172.         errmsg();
  173.         return;
  174.         }
  175.     return;
  176.     }
  177. else
  178. if((strncmp(func,band,cnt) == 0) && (cnt == 4))
  179.     {
  180.     bytcnt = 5;
  181.     if(strcmp(modifier,up) == 0)
  182.         cmd[4] = 0x6;
  183.     else
  184.     if(strcmp(modifier,dn) == 0)
  185.         cmd[4] = 0x7;
  186.     else
  187.         {
  188.         errmsg();
  189.         return;
  190.         }
  191.     return;
  192.     }
  193. else
  194. if((strncmp(func,split,cnt) == 0) && (cnt == 5))
  195.     {
  196.     bytcnt = 26;
  197.     cmd[4] = 0xA;
  198.     cmd[3] = 0x30;
  199.     return;
  200.     }
  201. else
  202. if((strncmp(func,clar,cnt) == 0) && (cnt == 4))
  203.     {
  204.     bytcnt = 26;
  205.     cmd[4] = 0xA;
  206.     cmd[3] = 0x40;
  207.     return;
  208.     }
  209. else
  210. if((strncmp(func,mtov,cnt) == 0) && (cnt == 4))
  211.     {
  212.     bytcnt = 26;
  213.     cmd[4] = 0xA;
  214.     cmd[3] = 0x50;
  215.     return;
  216.     }
  217. else
  218. if((strncmp(func,vtom,cnt) == 0) && (cnt == 4))
  219.     {
  220.     bytcnt = 86;
  221.     cmd[4] = 0xA;
  222.     cmd[3] = 0x60;
  223.     return;
  224.     }
  225. else
  226. if((strncmp(func,swap,cnt) == 0) && (cnt == 4))
  227.     {
  228.     bytcnt = 86;
  229.     cmd[4] = 0xA;
  230.     cmd[3] = 0x70;
  231.     return;
  232.     }
  233. else
  234. if((strncmp(func,prog,cnt) == 0) && (cnt == 4))
  235.     {
  236.     bytcnt = 5;
  237.     for(cnt=0;cnt<=15;cnt++)
  238.         func[cnt] = modifier[cnt];
  239.     cnt = parse(func);
  240.     if((strncmp(func,up,cnt) == 0) && (cnt == 2))
  241.         {
  242.         getnumber();
  243.         cmd[4] = 0x4;
  244.         cmd[3] = cmd[1];
  245.         cmd[2] = cmd[0];
  246.         }
  247.     else
  248.     if((strncmp(func,dn,cnt) == 0) && (cnt == 2))
  249.         {
  250.         getnumber();
  251.         cmd[4] = 0x5;
  252.         cmd[3] = cmd[1];
  253.         cmd[2] = cmd[0];
  254.         }
  255.     else
  256.         {
  257.         errmsg();
  258.         return;
  259.         }
  260.     return;
  261.     }
  262. else
  263. if((strncmp(func,freq,cnt) == 0) && (cnt == 4))
  264.     {
  265.     bytcnt = 5;
  266.     getnumber();
  267.     cmd[4] = 0x8;
  268.     return;
  269.     }
  270. else
  271. if((strncmp(func,vfo,cnt) == 0) && (cnt == 3))
  272.     {
  273.         bytcnt = 5;
  274.         cmd[4] = 0x9;
  275.     if(strcmp(modifier,a) == 0)
  276.         cmd[3] = 0x0;
  277.     else
  278.     if(strcmp(modifier,b) == 0)
  279.         cmd[3] = 0x1;
  280.     else
  281.     if(strcmp(modifier,mr) == 0)
  282.         cmd[3] = 0x2;
  283.     else
  284.         {
  285.         errmsg();
  286.         return;
  287.         }
  288.     return;
  289.     }
  290. else
  291. if((strncmp(func,mem,cnt) == 0) && (cnt == 3))
  292.     {
  293.         bytcnt = 8;
  294.         cmd[4] = 0xA;
  295.     if(strcmp(modifier,m0) == 0)
  296.         cmd[3] = 0x0;
  297.     else
  298.     if(strcmp(modifier,m1) == 0)
  299.         cmd[3] = 0x1;
  300.     else
  301.     if(strcmp(modifier,m2) == 0)
  302.         cmd[3] = 0x2;
  303.     else
  304.     if(strcmp(modifier,m3) == 0)
  305.         cmd[3] = 0x3;
  306.     else
  307.     if(strcmp(modifier,m4) == 0)
  308.         cmd[3] = 0x4;
  309.     else
  310.     if(strcmp(modifier,m5) == 0)
  311.         cmd[3] = 0x5;
  312.     else
  313.     if(strcmp(modifier,m6) == 0)
  314.         cmd[3] = 0x6;
  315.     else
  316.     if(strcmp(modifier,m7) == 0)
  317.         cmd[3] = 0x7;
  318.     else
  319.     if(strcmp(modifier,m8) == 0)
  320.         cmd[3] = 0x8;
  321.     else
  322.     if(strcmp(modifier,m9) == 0)
  323.         cmd[3] = 0x9;
  324.     else
  325.         {
  326.         errmsg();
  327.         return;
  328.         }
  329.     return;
  330.     }
  331. else
  332. if((strncmp(func,mode,cnt) == 0) && (cnt == 4))
  333.     {
  334.         bytcnt = 8;
  335.         cmd[4] = 0xA;
  336.     if(strcmp(modifier,lsb) == 0)
  337.         cmd[3] = 0x10;
  338.     else
  339.     if(strcmp(modifier,usb) == 0)
  340.         cmd[3] = 0x11;
  341.     else
  342.     if(strcmp(modifier,cw) == 0)
  343.         cmd[3] = 0x12;
  344.     else
  345.     if(strcmp(modifier,am) == 0)
  346.         cmd[3] = 0x13;
  347.     else
  348.     if(strcmp(modifier,fm) == 0)
  349.         cmd[3] = 0x14;
  350.     else
  351.     if(strcmp(modifier,fsk) == 0)
  352.         cmd[3] = 0x15;
  353.     else
  354.         {
  355.         errmsg();
  356.         return;
  357.         }
  358.     return;
  359.     }
  360. else
  361. if((strncmp(func,ham,cnt) == 0) && (cnt == 3))
  362.     {
  363.     bytcnt = 26;
  364.     cmd[4] = 0xA;
  365.     cmd[3] = 0x20;
  366.     return;
  367.     }
  368. else
  369. if((strncmp(func,gen,cnt) == 0) && (cnt == 3))
  370.     {
  371.     bytcnt = 26;
  372.     cmd[4] = 0xA;
  373.     cmd[3] = 0x21;
  374.     return;
  375.     }
  376. else
  377. if((strncmp(func,tone,cnt) == 0) && (cnt == 4))
  378.     {
  379.     bytcnt = 26;
  380.     for(cnt=0;cnt<=15;cnt++)
  381.         func[cnt] = modifier[cnt];
  382.     cnt = parse(func);
  383.     if((strncmp(func,loq,cnt) == 0) && (cnt == 3))
  384.         {
  385.         ptr = &*lstr;
  386.         if(cktone() == FALSE)
  387.             {
  388.             terr();
  389.             return;
  390.             }
  391.         else
  392.             {
  393.             getnumber();
  394.             cmd[4] = 0xC;
  395.             cmd[3] = cmd[1];
  396.             cmd[2] = cmd[0];
  397.             cmd[1] = 0x0;
  398.             }
  399.         }
  400.     else
  401.     if((strncmp(func,hiq,cnt) == 0) && (cnt == 3))
  402.         {
  403.         ptr = &*hstr;
  404.         if(cktone() == FALSE)
  405.             {
  406.             terr();
  407.             return;
  408.             }
  409.         else
  410.             {
  411.             getnumber();
  412.             cmd[4] = 0xC;
  413.             cmd[3] = cmd[1];
  414.             cmd[2] = cmd[0];
  415.             cmd[1] = 0x1;
  416.             }
  417.         }
  418.     else
  419.         {
  420.         errmsg();
  421.         return;
  422.         }
  423.     return;
  424.     }
  425. else
  426. if((strncmp(func,check,cnt) == 0) && (cnt == 5))
  427.     {
  428.     bytcnt = 86;
  429.     cmd[4] = 0x1;
  430.     return;
  431.     }
  432. else
  433. if((strncmp(func,aclr,cnt) == 0) && (cnt == 4))
  434.     {
  435.     bytcnt = 26;
  436.     cmd[4] = 0xA;
  437.     cmd[3] = 0x80;
  438.     return;
  439.     }
  440. else
  441. if((strncmp(func,quit,cnt) == 0) && (cnt == 4))
  442.     {
  443.     bytcnt = 86;
  444.     cmd[4] = 0x0;
  445.     cmd[3] = 0x1;
  446.     endprog = TRUE;
  447.     return;
  448.     }
  449. else
  450. if((strncmp(func,help,cnt) == 0) && (cnt == 4))
  451.     {
  452.     helpscreen();
  453.     getchar();
  454.     bytcnt = 86;
  455.     cmd[4] = 0x1;
  456.     return;
  457.     }
  458. else
  459.     gotoxy(0,22);
  460.     printf("                              ");
  461.     for(cnt = 0;cnt <= 30;cnt++) putchar(8);
  462.     printf("No such command as  [  %s  ]\n",func);
  463.     clear = TRUE;
  464.     return;
  465. }       /*end of match*/
  466.  
  467. void sendcmd()
  468. {
  469. int j,cnt;
  470. char echo[5];
  471.  
  472. cnt = 2;
  473. cmd[5] = 0;
  474. echo[5] = 0;
  475.  
  476. do
  477.     {
  478.     for(j = 0;j <= 4;j++)
  479.         {
  480.         comout(cmd[j]);
  481.         delay();
  482.         }
  483.     for(j=0;j<=4;j++)
  484.         {
  485.         echo[j] = comin();
  486.         delay();
  487.         }
  488.     --cnt;
  489.     }
  490. while((cnt != 0) && (strcmp(cmd,echo) != 0)) ;
  491.  
  492. if((cnt == 0) && (strcmp(cmd,echo) != 0))
  493.     {
  494.     gotoxy(0,22);
  495.     printf("There was a Transmission Error\n");
  496.     clear = TRUE;
  497.     xmiterror = TRUE;
  498.     return;
  499.     }
  500.  
  501. else
  502.     {
  503.     for(j=0;j<=4;j++)            //clear cmd[j] buffer
  504.         cmd[j] = 0;
  505.         cmd[4] = 11;              //load the acknowledgment byte
  506.     for(j=0;j<=4;j++)
  507.         {
  508.         comout(cmd[j]);           //send it
  509.         delay();
  510.         }
  511.     loadstatus();
  512.     }
  513. return;
  514. }       /*end of sendcmd*/
  515.  
  516. errmsg()
  517. {
  518. int cnt;
  519. gotoxy(0,22);
  520. printf("                              ");
  521. for(cnt = 0;cnt <= 30;cnt++) putchar(8);
  522. printf("Proper Modifier Required\n");
  523. clear = TRUE;
  524. }       /*end of error message*/
  525.  
  526. terr()
  527. {
  528. int cnt;
  529. gotoxy(0,22);
  530. printf("                              ");
  531. for(cnt = 0;cnt <= 30;cnt++) putchar(8);
  532. printf("Standard Tone Required\n");
  533. clear = TRUE;
  534. }       /*end of terr message*/
  535.  
  536. getnumber()
  537. {
  538. char *mod,tempbuf[9],*temp;
  539. int i,length;
  540. mod = modifier;
  541. temp = tempbuf;
  542. length = 0;
  543.  
  544. while(*mod != 0)
  545.     {
  546.     if(isdigit(*mod) == 0) *mod++;
  547.     else
  548.         {
  549.         *temp++ = *mod++;
  550.         length++;
  551.         }
  552.     }
  553. *temp = tempbuf[length - 1];
  554. for(i=0;i<=length;i++)
  555.     tempbuf[8 - i] = *temp--;
  556. for(i;i<=8;i++)
  557.     tempbuf[8 - i] = '0';
  558. tempbuf[8] = 0;
  559.  
  560. for(i=0;i<=7;i++)
  561.     {
  562.     tempbuf[i] = tempbuf[i] - 48;   //convert characters to digits
  563.     if(tempbuf[i] < 0)              //do not allow minus digits
  564.     tempbuf[i] = 0x0;
  565.     }
  566.  
  567. cmd[0] = tempbuf[7];
  568.     tempbuf[6] = tempbuf[6] << 4;
  569.     cmd[0] = cmd[0] | tempbuf[6];
  570. cmd[1] = tempbuf[5];
  571.     tempbuf[4] = tempbuf[4] << 4;
  572.     cmd[1] = cmd[1] | tempbuf[4];
  573. cmd[2] = tempbuf[3];
  574.     tempbuf[2] = tempbuf[2] << 4;
  575.     cmd[2] = cmd[2] | tempbuf[2];
  576. cmd[3] = tempbuf[1];
  577.     tempbuf[0] = tempbuf[0] << 4;
  578.     cmd[3] = cmd[3] | tempbuf[0];
  579. }       /*end of getnumber*/
  580.  
  581. loadstatus()
  582. {
  583. int k;
  584. int *stat;
  585. stat = status;
  586. for(k=0;k<=(bytcnt - 1);k++)
  587.     *stat++ = comin();
  588. }       /* end of loadstatus */
  589.  
  590. gotoxy(x,y)
  591. int x,y;
  592. {
  593.     printf("%c[%d;%dH",ESC,y,x);
  594. }       /* end of gotoxy */
  595.  
  596.  
  597. byte1()
  598. {
  599. int k;
  600. k = (bytcnt - 1);
  601.  
  602. if((status[k] & 0x80) != 0)
  603.     {
  604.     gotoxy(8,1);
  605.     printf("CAT Control         ON");
  606.     }
  607. else
  608.     {
  609.     gotoxy(8,1);
  610.     printf("CAT Control        OFF");
  611.     }
  612. if((status[k] & 0x20) != 0)
  613.     {
  614.     gotoxy(40,1);
  615.     printf("Memory channel recall     Active");
  616.     }
  617. else
  618.     {
  619.     gotoxy(40,1);
  620.     printf("Memory channel recall   Inactive");
  621.     }
  622. if((status[k] & 2) != 0)
  623.     {
  624.     gotoxy(8,2);
  625.     printf("Ham/General        Gen");
  626.     }
  627. else
  628.     {
  629.     gotoxy(8,2);
  630.     printf("Ham/General        Ham");
  631.     }
  632. if((status[k] & 4) != 0)
  633.     {
  634.     gotoxy(40,2);
  635.     printf("TX Inhibit                   OFF");
  636.     }
  637. else
  638.     {
  639.     gotoxy(40,2);
  640.     printf("TX Inhibit                    ON");
  641.     }
  642. if((status[k] & 0x10) != 0)
  643.     {
  644.     gotoxy(8,3);
  645.     printf("VFO                  B");
  646.     }
  647. else
  648.     {
  649.     gotoxy(8,3);
  650.     printf("VFO                  A");
  651.     }
  652. if((status[k] & 0x40) != 0)
  653.     {
  654.     gotoxy(40,3);
  655.     printf("Clarifier                     ON");
  656.     }
  657. else
  658.     {
  659.     gotoxy(40,3);
  660.     printf("Clarifier                    OFF");
  661.     }
  662. if((status[k] & 8) != 0)
  663.     {
  664.     gotoxy(8,4);
  665.     printf("Split               ON");
  666.     }
  667. else
  668.     {
  669.     gotoxy(8,4);
  670.     printf("Split              OFF");
  671.     }
  672. if((status[k] & 1) != 0)
  673.     {
  674.     gotoxy(40,4);
  675.     printf("PTT Status              Transmit");
  676.     }
  677. else
  678.     {
  679.     gotoxy(40,4);
  680.     printf("PTT Status               Receive");
  681.     }
  682. }       /* end of byte1 */
  683.  
  684. void cycles(k,x,y)
  685. int k,x,y;
  686. {
  687. char freq[12];
  688. int j,temp[3];
  689.  
  690. temp[3] = status[bytcnt - k--];
  691. temp[2] = status[bytcnt - k--];
  692. temp[1] = status[bytcnt - k--];
  693. temp[0] = status[bytcnt - k];
  694.  
  695. freq[10] = 0;
  696. freq[9] = temp[3];
  697. freq[9] = (freq[9] & 0xf) + 48;
  698. freq[8] = (temp[3] >> 4) + 48;
  699. freq[7] = '.';
  700. freq[6] = temp[2];
  701. freq[6] = (freq[6] & 0xf) + 48;
  702. freq[5] = (temp[2] >>4) + 48;
  703. freq[4] = temp[1];
  704. freq[4] = (freq[4] & 0xf) + 48;
  705. freq[3] = ',';
  706. freq[2] = (temp[1] >> 4) +48;
  707. freq[1] = temp[0];
  708. freq[1] = (freq[1] & 0xf) + 48;
  709. freq[0] = (temp[0] >> 4) + 48;
  710.  
  711. if((freq[0] == '0') && (freq[1] == '0') && (freq[2] == '0'))
  712.     freq[0] = freq[1] = freq[2] = freq[3] = ' ';
  713. if((freq[0] == '0') && (freq[1] == '0'))
  714.     freq[0] = freq[1] = ' ';
  715. if(freq[0] == '0')
  716.     freq[0] = ' ';
  717.  
  718. gotoxy(x,y);
  719. printf("Frequency %s,",freq);
  720. return;
  721. }       /* end of cycles */
  722.  
  723. void mode(m,x,y)
  724. int m,x,y;
  725. {
  726. int temp;
  727. temp = status[bytcnt - m];
  728. switch(temp & 0x7)
  729.     {
  730.     case(0) :
  731.         {
  732.         gotoxy(x,y);
  733.         printf("Mode LSB,");
  734.         break;
  735.         }
  736.     case(1) :
  737.         {
  738.         gotoxy(x,y);
  739.         printf("Mode USB,");
  740.         break;
  741.         }
  742.     case(2) :
  743.         {
  744.         gotoxy(x,y);
  745.         printf("Mode  CW,");
  746.         break;
  747.         }
  748.     case(3) :
  749.         {
  750.         gotoxy(x,y);
  751.         printf("Mode  AM,");
  752.         break;
  753.         }
  754.     case(4) :
  755.         {
  756.         gotoxy(x,y);
  757.         printf("Mode  FM,");
  758.         break;
  759.         }
  760.     case(5) :
  761.         {
  762.         gotoxy(x,y);
  763.         printf("Mode FSK,");
  764.         break;
  765.         }
  766.     default :
  767.         {
  768.         gotoxy(0,22);
  769.         printf("mode Error\n");
  770.         }
  771.     }
  772. return;
  773. }       /* end of mode */
  774.  
  775. void display()
  776. {
  777. int byte,x,y,k;
  778. if(bytcnt == 86)
  779.     CLRSCR;
  780.  
  781. if(bytcnt >= 5)
  782.     {
  783.     byte1();
  784.     drawline(2,5);
  785.     gotoxy(44,6);
  786.     putchar(' ');
  787.     x = 2; y = 6;
  788.     gotoxy(x,y);
  789.     printf("Operating  ");
  790.     byte = 5; x = 13; y = 6;
  791.     cycles(byte,x,y);
  792.     if(bytcnt == 5)
  793.         {
  794.         gotoxy(0,23);
  795.         CLREOL;
  796.         return;
  797.         }
  798.     }
  799.  
  800. if(bytcnt >= 8)
  801.     {
  802.     gotoxy(34,6);
  803.     putchar(' ');
  804.     byte = 7; x = 35; y = 6;
  805.     mode(byte,x,y);
  806.     byte = 8; x = 45; y = 6;
  807.     memchannel(byte,x,y);
  808.     shoband(bytcnt);
  809.     x = 61; y = 6;
  810.     gotoxy(x,y);
  811.     printf(", ");
  812.     byte = 6; x = 63; y = 6;
  813.     ctcsstone(byte,x,y);
  814.     if(bytcnt == 8)
  815.         {
  816.         gotoxy(0,23);
  817.         CLREOL;
  818.         return;
  819.         }
  820.     }
  821.  
  822. if(bytcnt >= 26)
  823.     {
  824.     drawline(2,7);
  825.     x = 11; y = 8;
  826.     gotoxy(x,y);
  827.     printf("VFO A ");
  828.     byte = 18; x = 22; y = 8;
  829.     cycles(byte,x,y);
  830.     byte = 20; x = 44; y = 8;
  831.     mode(byte,x,y);
  832.     byte = 19; x = 54; y = 8;
  833.     ctcsstone(byte,x,y);
  834.     x = 11; y = 9;
  835.     gotoxy(x,y);
  836.     printf("VFO B ");
  837.     byte = 24; x = 22; y = 9;
  838.     cycles(byte,x,y);
  839.     byte = 26; x = 44; y = 9;
  840.     mode(byte,x,y);
  841.     byte = 25; x = 54; y = 9;
  842.     ctcsstone(byte,x,y);
  843.     x = 11; y = 10;
  844.     gotoxy(x,y);
  845.     printf("Clarifier ");
  846.     byte = 12; x = 22; y = 10;
  847.     cycles(byte,x,y);
  848.     byte = 14; x = 44; y = 10;
  849.     mode(byte,x,y);
  850.     byte = 13; x = 54; y = 10;
  851.     ctcsstone(byte,x,y);
  852.     if(bytcnt == 26)
  853.         {
  854.         gotoxy(0,23);
  855.         CLREOL;
  856.         return;
  857.         }
  858.     }
  859.  
  860. if(bytcnt == 86)
  861.     {
  862.     drawline(2,11);
  863. for(k=0;k<=9;k++)
  864.     {
  865.     x = 7; y = (k + 12);
  866.     gotoxy(x,y);
  867.     printf("Memory Channel %d ",k);
  868.     byte = ((k * 6) + 30); x = 25; y = (k + 12);
  869.     cycles(byte,x,y);
  870.     byte = ((k * 6) + 32); x = 47; y = (k + 12);
  871.     mode(byte,x,y);
  872.     byte = ((k * 6) + 31); x = 57; y = (k + 12);
  873.     ctcsstone(byte,x,y);
  874.     {
  875.     gotoxy(0,23);
  876.     CLREOL;
  877.     }
  878.     }
  879.     }
  880. return;
  881. }       /* end of display */
  882.  
  883. memchannel(b,x,y)
  884. int b,x,y;
  885. {
  886. char temp[1];
  887. temp[0] = (status[bytcnt - b] + 48);
  888. temp[1] = 0;
  889. gotoxy(x,y);
  890. printf("Memory Channel %s",temp);
  891. }       /* end of memchannel */
  892.  
  893. ctcsstone(b,x,y)
  894. int b,x,y;
  895. {
  896. int tone;
  897. tone = (status[bytcnt - b] & 0x3f);
  898. gotoxy(x,y);
  899. printf("CTCSS Tone ");
  900. switch(tone)
  901.     {
  902.     case(0) : { puts("  67.0"); break; }
  903.     case(1) : { puts("  71.9"); break; }
  904.     case(2) : { puts("  77.0"); break; }
  905.     case(3) : { puts("  82.5"); break; }
  906.     case(4) : { puts("  88.5"); break; }
  907.     case(5) : { puts("  94.8"); break; }
  908.     case(6) : { puts(" 100.0"); break; }
  909.     case(7) : { puts(" 103.5"); break; }
  910.     case(8) : { puts(" 107.2"); break; }
  911.     case(9) : { puts(" 110.9"); break; }
  912.     case(10) : { puts(" 114.8"); break; }
  913.     case(11) : { puts(" 118.8"); break; }
  914.     case(12) : { puts(" 123.0"); break; }
  915.     case(13) : { puts(" 127.3"); break; }
  916.     case(14) : { puts(" 131.8"); break; }
  917.     case(15) : { puts(" 136.5"); break; }
  918.     case(16) : { puts(" 141.3"); break; }
  919.     case(17) : { puts(" 146.2"); break; }
  920.     case(18) : { puts(" 151.4"); break; }
  921.     case(19) : { puts(" 156.7"); break; }
  922.     case(20) : { puts(" 162.2"); break; }
  923.     case(21) : { puts(" 167.9"); break; }
  924.     case(22) : { puts(" 173.8"); break; }
  925.     case(23) : { puts(" 179.9"); break; }
  926.     case(24) : { puts(" 186.2"); break; }
  927.     case(25) : { puts(" 192.8"); break; }
  928.     case(26) : { puts(" 203.5"); break; }
  929.     case(27) : { puts(" 210.7"); break; }
  930.     case(28) : { puts(" 218.1"); break; }
  931.     case(29) : { puts(" 225.7"); break; }
  932.     case(30) : { puts(" 233.6"); break; }
  933.     case(31) : { puts(" 241.8"); break; }
  934.     case(32) : { puts(" 250.3"); break; }
  935.     case(33) : { puts("C 67.0"); break; }
  936.     case(34) : { puts("C 71.9"); break; }
  937.     case(35) : { puts("C 74.7"); break; }
  938.     case(36) : { puts("C 77.0"); break; }
  939.     case(37) : { puts("C 79.7"); break; }
  940.     case(38) : { puts("C 82.5"); break; }
  941.     case(39) : { puts("C 85.4"); break; }
  942.     case(40) : { puts("C 88.5"); break; }
  943.     case(41) : { puts("C 91.5"); break; }
  944.     default :
  945.         {
  946.         gotoxy(0,22);
  947.         printf("Where did it get that tone?");
  948.         }
  949.     }
  950. }       /* end of ctcsstone */
  951.  
  952. isin(tone)
  953. char *tone;
  954. {
  955. int index;
  956.  
  957. if(strlen(tone) == 0)
  958.     return(FALSE);
  959. else
  960.     {
  961.     index = -1;
  962.         do
  963.             {
  964.             if(! strcmp(tone,ptr[++index]))
  965.             return(1);
  966.             }
  967.         while(strcmp(EDTB,ptr[index]));
  968.             return(0);
  969.     }
  970. }       /* end of isin() */
  971.  
  972. cktone()
  973. {
  974. char buf[8];
  975. int i;
  976. i = 0;
  977. while(modifier[i] != 0)
  978.     {
  979.     buf[i] = modifier[i];
  980.     i++;
  981.     }
  982. buf[i] = 0;
  983. if(isin(&buf) == FALSE) return(FALSE);
  984. else
  985. if(isin(&buf) == TRUE) return(TRUE);
  986. }       /* end of cktone() */
  987.  
  988. drawline(x,y)
  989. int x,y;
  990. {
  991. int i;
  992. gotoxy(x,y);
  993. for(i=0;i<=77;i++)
  994.     putchar(0xC4);
  995. }       /* end of drawline */
  996.  
  997. shoband()
  998. {
  999. int band;
  1000. band = status[bytcnt - 7];
  1001. band = (band & 120);
  1002. band = (band >> 3);
  1003. if(status[bytcnt - 2] >= 0x44) band = 15;
  1004. gotoxy(40,22);
  1005. printf("Band = ");
  1006. switch(band)
  1007.     {
  1008.     case(1) : { printf("  1,500.00 MHZ -   2,499.99 MHZ"); break; }
  1009.     case(2) : { printf("  2,500.00 MHZ -   3,999.99 MHZ"); break; }
  1010.     case(3) : { printf("  4,000.00 MHZ -   7,499.99 MHZ"); break; }
  1011.     case(4) : { printf("  7,500.00 MHZ -  10,499.99 MHZ"); break; }
  1012.     case(5) : { printf(" 10,500.00 MHZ -  14,499.99 MHZ"); break; }
  1013.     case(6) : { printf(" 14,500.00 MHZ -  18,499.99 MHZ"); break; }
  1014.     case(7) : { printf(" 18,500.00 MHZ -  21,499.99 MHZ"); break; }
  1015.     case(8) : { printf(" 21,500.00 MHZ -  24,999.99 MHZ"); break; }
  1016.     case(9) : { printf(" 25,000.00 MHZ -  29,999.99 MHZ"); break; }
  1017.     case(10) : { printf(" 50,000.00 MHZ -  59,999.99 MHZ"); break; }
  1018.     case(11) : { printf("144,000.00 MHZ - 149,999.99 MHZ"); break; }
  1019.     case(12) : { printf("430,000.00 MHZ - 439,999.99 MHZ"); break; }
  1020.     case(13) : { printf("    000.00 MHZ -     499.99 MHZ"); break; }
  1021.     case(14) : { printf("    500.00 MHZ -   1,499.99 MHZ"); break; }
  1022.     case(15) : { printf("440,000.00 MHZ - 449,999.99 MHZ"); break; }
  1023.     default : { printf("Frequency outside of Range"); break; }
  1024.     }
  1025. }       /* end of shoband */
  1026.  
  1027. helpscreen()
  1028. {
  1029. CLRSCR;
  1030. printf("COMMAND &  MODIFIERS if ANY        FUNCTION\n");
  1031. printf("check\t\t\t\tGet the status of functions, and redraw screen\n");
  1032. printf("gen\t\t\t\tGeneral coverage receiver\n");
  1033. printf("ham\t\t\t\tAmateur bands only\n");
  1034. printf("quit\t\t\t\tTurn CAT off and terminate program\n");
  1035. printf("up\t\t\t\tTune up 10hz\n");
  1036. printf("dn\t\t\t\tTune down 10hz\n");
  1037. printf("prog\tup/dn & amount\t\tTune Up/Down 00 00 to 99 99 or 0-99.99khz\n");
  1038. printf("band\tup/dn\t\t\tStep Up/Down one ham band or .5 Mhz in Gen\n");
  1039. printf("freq\t(actual)\t\tTune to entered Frequency\n");
  1040. printf("vfo\ta/b/mr\t\t\tVFO/Memory select\n");
  1041. printf("mem\tm(0,1,2,3,4,5,6,7,8,9)\tMemory select\n");
  1042. printf("mode\tlsb/usb/cw/am/fm/fsk\tMode select\n");
  1043. printf("split\t\t\t\tToggle split Frequency operation on/off\n");
  1044. printf("clar\t\t\t\tToggle Clarifier on/off\n");
  1045. printf("mtov\t\t\t\tMemory to VFO\n");
  1046. printf("vtom\t\t\t\tVFO to Memory\n");
  1047. printf("swap\t\t\t\tSwap VFO and Memory\n");
  1048. printf("aclr\t\t\t\tTurn off Split, Clar and Offset\n");
  1049. printf("tone  loq/hiq ctcss frequency\tSet CTCSS TONE\n");
  1050. printf("help\t\t\t\tThis display\n");
  1051. printf("diskmem\t\t\t\tStore or Recall in or from disk Memory\n");
  1052. printf("\t\tPress Enter to return to the control program ---  ");
  1053. }       /*      end of helpscreen       */
  1054.  
  1055. /*initialize com port ( in this case com2)*/
  1056. /*done in assembler for simplicity*/
  1057. initcom()
  1058. {
  1059. __asm
  1060.         {
  1061.         mov     ah,0
  1062.         mov     dx,0            //0 for com1, 1 for com2
  1063.         mov     al,11000111b    //4800 baud, 2 stop bits
  1064.                                         //8 data bits, no parity
  1065.         int     14h
  1066.         }
  1067. }               /*end of initcom*/
  1068.  
  1069. delay()
  1070. {
  1071. int cnt;
  1072.       /*define the value of FACTOR low, even 0 for slow machines*/
  1073.         /*such as 286 @ 8 mhz, 800 works on my 486 @ 66 or @ 33 mhz*/
  1074. for(cnt = 0;cnt <= FACTOR;cnt++) ;
  1075. }               /*end of delay*/
  1076.  
  1077. comin()
  1078. {
  1079. int j;
  1080. unsigned char ch;
  1081. j = TIMEOUT;
  1082. /*use 0x3fd for com1 or 0x2fd for com2*/
  1083. while((_inp(0x3fd) & 0x01) == 0)
  1084. {
  1085.     --j;
  1086.     if(j == 0)
  1087.         break;
  1088. }
  1089. if(j == 0)
  1090. ch = 0;
  1091. else
  1092. /*use 0x3fd for com1 or 0x2fd for com2*/
  1093. ch = (_inp(0x3f8));
  1094. return(ch);
  1095. }       /*end of comin*/
  1096.  
  1097. comout(ch)
  1098. char ch;
  1099. {
  1100. /*use 0x3fd for com1 or 0x2fd for com2*/
  1101. while((_inp(0x3fd) & 0x20) == 0) ;
  1102.      _outp(0x3f8,ch);
  1103. }       /*end of comout*/
  1104.  
  1105. testport()
  1106. {
  1107. int j;
  1108. j = TIMEOUT;
  1109. /*use 0x3fd for com1 or 0x2fd for com2*/
  1110. while( (_inp(0x3fe) & 0x30) == 0)
  1111.         {
  1112.         --j;
  1113.         if(j == 0) return(0xff);
  1114.         }
  1115. return(0);
  1116. }               /*end of testport*/
  1117.  
  1118. startup()
  1119. {
  1120. char func[5],*edit;
  1121. edit = "edit";
  1122. helpscreen();
  1123. gotoxy(0,23);
  1124. CLREOL;
  1125. printf("edit\t    Enter edit now to edit disk memory files or\n");
  1126. printf("\t    Press Enter to proceed to the control program ---  ");
  1127. gets(func);
  1128. if(strlen(func) == 0) ;
  1129. else
  1130. if(strncmp(func,edit,4) == 0)
  1131.     edit_control();
  1132. CLRSCR;
  1133. initcom();
  1134.  
  1135. if(testport() != 0)    
  1136.     {
  1137.     gotoxy(10,10);
  1138.     printf("Check the cable connections and turn on the interface device.\n");
  1139.     gotoxy(0,23);
  1140.     exit(0);
  1141.     }
  1142. bytcnt = 86;
  1143. cmd[3] = 0x0;
  1144. cmd[4] = 0x0;
  1145. sendcmd();
  1146. catflag = TRUE;    //the FT-767GX CAT function has been turned on
  1147. display();
  1148. }       /*end of startup*/
  1149.  
  1150. is_ansi()
  1151. {
  1152. FILE *fp,*fopen();
  1153. char ch,buffer[80],*ptr;
  1154. char drive,file[15] = "0:\\config.sys";
  1155. int flag;
  1156.  
  1157. _asm {
  1158.         mov     ax,3305h
  1159.         int     21h
  1160.         mov     drive,dl
  1161.         }
  1162.  
  1163. file[0] = (drive + 64);
  1164. if((fp = fopen(file,"r")) == NULL)
  1165.     {
  1166.     printf("File %s did not open.\n",file);
  1167.     exit(0);
  1168.     } 
  1169.  
  1170. flag = 0;
  1171. ptr = buffer;
  1172. memset(ptr,0,80);
  1173. while((ch = getc(fp)) != EOF)
  1174.     {
  1175.         *ptr++ = tolower(ch);
  1176.         if(ch == '\n')
  1177.             {
  1178.             if((strstr(buffer,"ansi.sys")) != 0)
  1179.                 {
  1180.                 flag = 1;
  1181.                 break;
  1182.                 }
  1183.             else
  1184.                 {
  1185.                 ptr = buffer;
  1186.                 memset(ptr,0,80);
  1187.                 }
  1188.             }
  1189.     }
  1190. fclose(fp);
  1191. if(flag == 0)
  1192. {
  1193. system("cls");
  1194. printf("\n\n\n\n\n\n\n\n");
  1195. printf("\tSome commands from the ANSI.SYS driver are required by this\n");
  1196. printf("\tprogram.  The driver does not appear to be in the boot disk's\n"); 
  1197. printf("\tCONFIG.SYS file.\n\n");  
  1198. printf("\tPlease add a line such as DEVICE=C:\\DOS\\ANSI.SYS to the\n");
  1199. printf("\tCONFIG.SYS file and reboot the system.\n");
  1200. printf("\n\n\n\n\n\n\n");
  1201. exit(0);
  1202. }
  1203. }       /* end of is_ansi */
  1204.  
  1205. main()
  1206. {
  1207. char func[15],*caton,*catoff,*recall,*diskmem;
  1208. int i,k;
  1209. endprog = FALSE;
  1210. catflag = FALSE;
  1211. caton = "cat on";
  1212. catoff = "cat off";
  1213. diskmem = "diskmem";
  1214.  
  1215. is_ansi();
  1216. startup();      
  1217. for(;;)
  1218.     {
  1219.     clear = FALSE;
  1220.     xmiterror = FALSE;
  1221.     for(i=0;i<=15;i++)
  1222.         func[i] = 0;
  1223.     for(i=0;i<=10;i++)
  1224.         cmd[i] = 0;
  1225.     bytcnt = 0;
  1226.     gotoxy(0,23);
  1227.     putchar('>');
  1228.     CLREOL;
  1229.  
  1230.     gets(func);
  1231.     if((strncmp(func,catoff,6) == 0) && (catflag == TRUE)) ;
  1232.     else
  1233.     if((strncmp(func,caton,5) == 0) && (catflag == TRUE)) ; 
  1234.     else 
  1235.     if(strlen(func) == 0) ;
  1236.     else
  1237.     if((strncmp(func,diskmem,7) == 0))
  1238.         {
  1239.         disk_memory_control();
  1240.         do_it("check");
  1241.         display();
  1242.         }
  1243.     else
  1244.         {
  1245.         gotoxy(0,22);
  1246.         printf("                                  \n");
  1247.         match(func,parse(func));
  1248.             if(clear == FALSE)
  1249.                 {
  1250.                 sendcmd();
  1251.                 if(xmiterror == TRUE) ;
  1252.             else
  1253.                 display();
  1254.                 }
  1255.         }
  1256.         if(endprog == TRUE) break;
  1257.     }
  1258. }       /*end of main*/
  1259.  
  1260.  
  1261. void disk_memory_control(void)
  1262. {
  1263. int option;
  1264. do
  1265. {
  1266.     clrscr();
  1267.     printf("\t\t\tAccess to extra memories on disk\n\n");
  1268.     printf("\t\t\t General Coverage Reception and\n");
  1269.     printf("\t\t\t Amateur Band Simplex operation\n\n");
  1270.     printf("\t   1  - Store VFO A  to General Disk Memory\n");
  1271.     printf("\t   2  - Recall General Disk Memory to VFO A\n");
  1272.     printf("\t   3  - View the General Stations file\n");
  1273.     printf("\t   4  - Add Stations to General Coverage disk memory by hand\n");
  1274.     printf("\t   5  - Remove Stations from General Coverage disk memory\n");
  1275.     printf("\n\t\t\t Amateur Band Split Frequency\n");
  1276.     printf("\t\t\t    and Repeater Operation\n\n");
  1277.     printf("\t   6  - Store VFOs to Amateur Band Repeater Disk Memory\n");
  1278.     printf("\t   7  - Recall Amateur Band Repeater Disk Memory to VFOs\n");
  1279.     printf("\t   8  - View the Amateur Band Repeater Stations file\n");
  1280.     printf("\t   9  - Add Stations to Amateur Repeater disk memory by hand\n");
  1281.     printf("\t   10 - Remove Stations from Amateur Repeater disk memory\n");
  1282.     printf("\n\t   11 - To return to main program\n\n");
  1283.     printf("\t        Enter selection  ---   ");
  1284.     scanf("%d",&option);
  1285.     fflush(stdin);
  1286.     }
  1287. while((option < 1) || (option > 11));
  1288. selection(option);
  1289. }    /*end of disk_memory_control*/
  1290.  
  1291. int selection(int choice)
  1292. {
  1293.     switch(choice)
  1294.         {
  1295.         case 1:     store(1); break;
  1296.         case 2:     recall(2); break;
  1297.         case 3:   examine_files(3); break;
  1298.         case 4:     add_station(4); break;
  1299.         case 5:     delete_station(5); break;
  1300.         case 6:     store(6); break;
  1301.         case 7:     recall(7); break;
  1302.         case 8:   examine_files(8); break;
  1303.         case 9:     add_station(9); break;
  1304.         case 10:  delete_station(10); break;
  1305.         default: return(0);
  1306.         }
  1307. }    /*end of selection*/
  1308.  
  1309. void store(int num)
  1310. {
  1311.     int k;
  1312.     clrscr();
  1313.     do_it("check");
  1314.     k = (bytcnt - 1);
  1315.     if((status[k] & 0x10) != 0)
  1316.         {
  1317.         gotoxy(28,10);
  1318.         printf("VFO B is the active VFO");
  1319.         }
  1320.     else
  1321.         {
  1322.         gotoxy(28,10);
  1323.         printf("VFO A is the active VFO");
  1324.         }
  1325.     gotoxy(22,23);
  1326.     printf("Press Enter to contiue, ESC to abort");
  1327.     if(_getch() == ESC) return;
  1328.     if((num == 1) || (num == 6))
  1329.         add_station(num);
  1330. }    /*end of store*/
  1331.  
  1332. void examine_files(int num)
  1333. {
  1334. int record_cnt;
  1335.  
  1336. record_cnt = loadfile(num);
  1337. if(record_cnt != -3)
  1338.     viewfile(record_cnt,num);
  1339. }    /*end of examine_files*/
  1340.  
  1341. int add_station(int num)
  1342. {
  1343. int record_cnt;
  1344.  
  1345. for(;;)
  1346. {
  1347.     record_cnt = loadfile(num);
  1348.     if(record_cnt > -2)
  1349.         {
  1350.         if(num < 6)
  1351.             {
  1352.             if(gen_insert(record_cnt,num) == 1)
  1353.                 viewfile((record_cnt + 1),num);
  1354.             }
  1355.         if(num >= 6)
  1356.             
  1357.             {
  1358.             if(rep_insert(record_cnt,num) == 1)
  1359.                 viewfile((record_cnt + 1),num);
  1360.             }
  1361.         }    
  1362.     else
  1363.         if(record_cnt == -4)
  1364.             {
  1365.               record_cnt = -1;
  1366.             if(num < 6)
  1367.                 {
  1368.                 if(gen_insert(record_cnt,num) == 1)
  1369.                     viewfile((record_cnt + 1),num);
  1370.                 }    
  1371.             if(num >= 6)
  1372.                 {
  1373.                 if(rep_insert(record_cnt,num) == 1)
  1374.                     viewfile((record_cnt + 1),num);
  1375.                 }        
  1376.             }
  1377.         else
  1378.         if(record_cnt == -3) break;
  1379.     clrscr();
  1380. if((num == 1) || (num == 6)) break;
  1381. gotoxy(0,10);
  1382. printf("\n\n\t\tAdd another station? y or n --- ");
  1383. if(getreply() == 1) break;
  1384. }
  1385. }    /*end of add_station*/
  1386.  
  1387. int delete_station(int num)
  1388. {
  1389. int record_cnt,del_rec;
  1390.  
  1391. for(;;)
  1392. {
  1393.     record_cnt = loadfile(num);
  1394.     if(record_cnt == -3) break;
  1395. do
  1396. {
  1397.     viewfile(record_cnt,num);
  1398.     gotoxy(0,24);
  1399.     CLREOL;
  1400.     gotoxy(13,24);
  1401.     printf("Enter the MEM number of the station to be removed --- ");
  1402.     scanf("%d",&del_rec);
  1403. }
  1404. while((del_rec < 1) || (del_rec > (record_cnt + 1)));
  1405.  
  1406. if((del_rec == 1) && (record_cnt == 0))
  1407.     {
  1408.     if(num < 6)
  1409.         system("del general.dat");
  1410.     if(num > 6)
  1411.         system("del repeater.dat");
  1412.     }    
  1413. else
  1414.     {    
  1415.     remove_record(del_rec,record_cnt,num);
  1416.     savedata(record_cnt - 1,num);
  1417.     clrscr();
  1418.     gotoxy(0,10);
  1419.     printf("\n\n\t\tRemove another station? y or n --- ");
  1420.     if(getreply() == 1) break;
  1421.     }
  1422. }
  1423. }    /*end of delete_station*/
  1424.  
  1425. int getreply(void)
  1426. {
  1427. char ch;
  1428. #undef toupper
  1429. do
  1430.     {
  1431.     ch = toupper(_getch());
  1432.     }     while((ch != 'Y') && (ch != 'N'));
  1433.     if(ch == 'Y') return(0);
  1434.     else
  1435.     if(ch == 'N') return(1);
  1436. }       /*end of getreply*/
  1437.  
  1438. void backup(int spaces)
  1439. {
  1440. int i;
  1441. for(i = 0;i <= spaces;++i) BACKSPACE;
  1442. }       /*end of backup*/
  1443.  
  1444. int gen_insert(int rcnt , int num)
  1445. {
  1446. int len,recnum;
  1447. struct general *pt1,*pt2;
  1448. if(num == 4)
  1449.     input_data(4);
  1450. else
  1451.     if(num == 1)
  1452.         get_data(1);
  1453. for(recnum = 0;recnum <= rcnt;++recnum)
  1454.     {
  1455.     if(atol(gentemp.freq) < atol(g[recnum].freq))
  1456.         break;
  1457.     else
  1458.     if(atol(gentemp.freq) == atol(g[recnum].freq))
  1459.         {
  1460.         printf("\n\n\n\n\t\t\tA station is in the list at %s\n",g[recnum].freq);
  1461.         printf("\n\t\t\tPress any key to continue ---  ");
  1462.         _getch();
  1463.         return(0);
  1464.         }
  1465.     else
  1466.     if(atol(gentemp.freq) > atol(g[recnum].freq))
  1467.         ;
  1468.     }
  1469. sprintf(gentemp.rec,"%d",(recnum));
  1470. len = sizeof(struct general);
  1471. if(recnum > rcnt)
  1472.     {
  1473.     pt1 = &gentemp;
  1474.     pt2 = &g[recnum];
  1475.     memcpy(pt2,pt1,len);
  1476.     }
  1477. else
  1478.     {    
  1479.     pt1 = &g[recnum + 1];
  1480.     pt2 = &g[recnum];
  1481.     memmove(pt1,pt2,(rcnt + 1 - recnum) * len);
  1482.     pt1 = &gentemp;
  1483.     pt2 = &g[recnum];
  1484.     memcpy(pt2,pt1,len);
  1485.     }
  1486. reindex(rcnt,num,1);
  1487. savedata(rcnt + 1,num);
  1488. return(1);
  1489. }       /*end of gen_insert*/
  1490.  
  1491. int loadfile(int num)
  1492. {
  1493. FILE *fp,*fopen();
  1494. int i;
  1495. char buff[40],*p1,*p2;
  1496.  
  1497. if(num < 6)
  1498.     {
  1499.     if((fp=fopen("general.dat","r")) == 0)
  1500.         {
  1501.         clrscr();
  1502.         printf("\n\n\n\n\n\n");
  1503.         printf("\t\tFile GENERAL.DAT does not exist.\n");
  1504.         if((num == 2) || (num == 3) || (num == 5))
  1505.             {
  1506.             press_enter(90,24);
  1507.             return(-3);
  1508.             }
  1509.         else
  1510.             {
  1511.             printf("\t\tShould I create a new file? y or n ---  ");
  1512.             i = getreply();
  1513.                 if(i == 1) return(-3);
  1514.                 if(i == 0) return(-4);
  1515.             }
  1516.         }
  1517.     }
  1518.  
  1519. if(num >= 6)
  1520.     {
  1521.     if((fp=fopen("repeater.dat","r")) == 0)
  1522.         {
  1523.         clrscr();
  1524.         printf("\n\n\n\n\n\n");
  1525.         printf("\t\tFile REPEATER.DAT does not exist.\n");
  1526.         if((num == 7) || (num == 8) || (num == 10))
  1527.             {
  1528.             press_enter(90,24);
  1529.             return(-3);
  1530.             }
  1531.         else
  1532.             {
  1533.             printf("\t\tShould I create a new file? y or n ---  ");
  1534.             i = getreply();
  1535.                 if(i == 1) return(-3);
  1536.                 if(i == 0) return(-4);
  1537.             }
  1538.         }
  1539.     }    
  1540. i = 0;
  1541. while(!feof(fp))
  1542. {
  1543.         p1 = buff;
  1544.     if(num < 6)
  1545.         p2 = g[i].rec;
  1546.     if(num >= 6)
  1547.         p2 = r[i].rec;
  1548.         fgets(p1,5,fp);
  1549.     while(*p1 != '\n')
  1550.         *p2++ = *p1++;
  1551.     
  1552.     if(num < 6)
  1553.         {
  1554.         p1 = buff;
  1555.         p2 = g[i].freq;
  1556.         fgets(p1,10,fp);
  1557.     while(*p1 != '\n')
  1558.         *p2++ = *p1++;
  1559.         }
  1560.  
  1561.     if(num >= 6)
  1562.         {
  1563.         p1 = buff;
  1564.         p2 = r[i].afreq;
  1565.         fgets(p1,10,fp);
  1566.     while(*p1 != '\n')
  1567.         *p2++ = *p1++;
  1568.  
  1569.         p1 = buff;
  1570.         p2 = r[i].bfreq;
  1571.         fgets(p1,10,fp);
  1572.     while(*p1 != '\n')
  1573.         *p2++ = *p1++;
  1574.         }
  1575.  
  1576.         p1 = buff;
  1577.     if(num < 6)
  1578.         p2 = g[i].mode;
  1579.     if(num >= 6)
  1580.         p2 = r[i].mode;
  1581.         fgets(p1,5,fp);
  1582.     while(*p1 != '\n')
  1583.         *p2++ = *p1++;
  1584.  
  1585.     if(num < 6) ;
  1586.     if(num >= 6)
  1587.         {
  1588.         p1 = buff;
  1589.         p2 = r[i].tone;
  1590.         fgets(p1,9,fp);
  1591.     while(*p1 != '\n')
  1592.         *p2++ = *p1++;
  1593.         }
  1594.  
  1595.         p1 = buff;
  1596.     if(num < 6)
  1597.         p2 = g[i].call;
  1598.     if(num >= 6)
  1599.         p2 = r[i].call;
  1600.         fgets(p1,10,fp);
  1601.     while(*p1 != '\n')
  1602.         *p2++ = *p1++;
  1603.  
  1604.         p1 = buff;
  1605.     if(num < 6)
  1606.         p2 = g[i].loc;
  1607.     if(num >= 6)
  1608.         p2 = r[i].loc;
  1609.         fgets(p1,36,fp);
  1610.     while(*p1 != '\n')
  1611.         *p2++ = *p1++;
  1612.     ++i;
  1613.     }
  1614. fclose(fp);
  1615. return(i - 2);
  1616. }       /*end of loadfile*/
  1617.  
  1618. int rep_insert(int rcnt , int num)
  1619. {
  1620. int len,recnum;
  1621. struct repeater *pt1,*pt2;
  1622. if(num == 9)
  1623.     input_data(9);
  1624. else
  1625.     if(num == 6)
  1626.         get_data(6);
  1627. for(recnum = 0;recnum <= rcnt;++recnum)
  1628.     {
  1629.     if(atol(reptemp.afreq) < atol(r[recnum].afreq))
  1630.         break;
  1631.     else
  1632.     if(atol(reptemp.afreq) == atol(r[recnum].afreq))
  1633.         {
  1634.         printf("\n\n\n\n\t\t\tA station is in the list at %s\n",r[recnum].afreq);
  1635.         printf("\n\t\t\tPress any key to continue ---  ");
  1636.         _getch();
  1637.         return(0);
  1638.         }
  1639.     else
  1640.     if(atol(reptemp.afreq) > atol(r[recnum].afreq))
  1641.         ;
  1642.     }
  1643. sprintf(reptemp.rec,"%d",(recnum));
  1644. len = sizeof(struct repeater);
  1645. if(recnum > rcnt)
  1646.     {
  1647.     pt1 = &reptemp;
  1648.     pt2 = &r[recnum];
  1649.     memcpy(pt2,pt1,len);
  1650.     }
  1651. else
  1652.     {       
  1653.     pt1 = &r[recnum + 1];
  1654.     pt2 = &r[recnum];
  1655.     memmove(pt1,pt2,(rcnt + 1 - recnum) * len);
  1656.     pt1 = &reptemp;
  1657.     pt2 = &r[recnum];
  1658.     memcpy(pt2,pt1,len);
  1659.     }
  1660. reindex(rcnt,num,1);
  1661. savedata(rcnt + 1,num);
  1662. return(1);
  1663. }       /*end of rep_insert*/
  1664.  
  1665. int savedata(int maxcnt, int num)
  1666. {
  1667. FILE *fp,*fopen();
  1668. int i;
  1669. if(maxcnt < 0)
  1670. return(0);
  1671.  
  1672. if(num < 6)
  1673. {
  1674. if((fp=fopen("general.dat","w")) == 0)
  1675.     {
  1676.     clrscr();
  1677.     printf("\n\n\n\n\n\n\n\t\t\tFile GENERAL.DAT Open Failed\n\n\n");
  1678.     if((fp=fopen("general.dat","r")) != 0)
  1679.         {
  1680.         printf("\t\tWrite protected disk.\n\n");
  1681.         fclose(fp);
  1682.         }
  1683.     return(0);
  1684.     }
  1685. }
  1686.  
  1687. if(num  >= 6)
  1688. {
  1689. if((fp=fopen("repeater.dat","w")) == 0)
  1690.     {
  1691.     clrscr();
  1692.     printf("\n\n\n\n\n\n\n\t\t\tFile REPEATER.DAT Open Failed\n\n\n");
  1693.     if((fp=fopen("repeater.dat","r")) != 0)
  1694.         {
  1695.         printf("\t\tWrite protected disk.\n\n");
  1696.         fclose(fp);
  1697.         }
  1698.     return(0);
  1699.     }
  1700. }
  1701.  
  1702. if(num < 6)
  1703. {
  1704. for(i = 0;i <= maxcnt; ++i)
  1705.     {
  1706.     fprintf(fp,"%s\n",g[i].rec);
  1707.     fprintf(fp,"%s\n",g[i].freq);
  1708.     fprintf(fp,"%s\n",g[i].mode);
  1709.     fprintf(fp,"%s\n",g[i].call);
  1710.     fprintf(fp,"%s\n",g[i].loc);
  1711.     }
  1712. fclose(fp);
  1713. return(0);
  1714. }
  1715.  
  1716. if(num >= 6)
  1717. {
  1718. for(i = 0;i <= maxcnt; ++i)
  1719.     {
  1720.     fprintf(fp,"%s\n",r[i].rec);
  1721.     fprintf(fp,"%s\n",r[i].afreq);
  1722.     fprintf(fp,"%s\n",r[i].bfreq);
  1723.     fprintf(fp,"%s\n",r[i].mode);
  1724.     fprintf(fp,"%s\n",r[i].tone);
  1725.     fprintf(fp,"%s\n",r[i].call);
  1726.     fprintf(fp,"%s\n",r[i].loc);
  1727.     }
  1728. fclose(fp);
  1729. return(0);
  1730. }
  1731. }       /*end of savedata*/
  1732.  
  1733. void input_data(int num)
  1734. {
  1735. char buf[42],*p1,*p2;
  1736. #undef toupper 
  1737. if(num == 4)
  1738.     memset(&gentemp,0,sizeof(struct general) + 1);
  1739. if(num == 9)
  1740.     memset(&reptemp,0,sizeof(struct repeater) + 1);
  1741. clrscr();
  1742. printf("\n\n\n");
  1743. while(TRUE)
  1744.     {
  1745.     if(num == 4)
  1746.     {
  1747.     printf("Enter Station's Frequency             ________");
  1748.     backup(7);
  1749.     gets(gentemp.freq);
  1750.     if(strlen(gentemp.freq) <= 8 && strlen(gentemp.freq) > 0) break;
  1751.     }
  1752.     if(num == 9)
  1753.     {
  1754.     printf("Enter Station's VFO A Frequency       ________");
  1755.     backup(7);
  1756.     gets(reptemp.afreq);
  1757.     if(strlen(reptemp.afreq) <= 8 && strlen(reptemp.afreq) > 0) break;
  1758.     }
  1759.     }
  1760. if(num == 4) ;
  1761. else
  1762. if(num == 9)
  1763. {
  1764. while(TRUE)
  1765.     {
  1766.     printf("Enter Station's VFO B Frequency       ________");
  1767.     backup(7);
  1768.     if(num == 9)
  1769.     gets(reptemp.bfreq);
  1770.     if(strlen(reptemp.bfreq) <= 8 && strlen(reptemp.bfreq) > 0) break;
  1771.     }
  1772. }
  1773.  
  1774. while(TRUE)
  1775.     {
  1776.     printf("Enter Station's Mode                  ___");
  1777.     backup(2);
  1778.     p1 = buf;
  1779.     if(num == 4)
  1780.         p2 = gentemp.mode;
  1781.     if(num == 9)
  1782.         p2 = reptemp.mode;
  1783.     gets(buf);
  1784.     if(strlen(buf) <= 3 && strlen(buf) > 0) break;
  1785.     }
  1786.     while(*p1 != 0)
  1787.         *p2++ = toupper(*p1++);
  1788.         *p2 = 0;
  1789.  
  1790. if(num == 4) ;
  1791. else
  1792. {
  1793. if(num == 9)
  1794.     {
  1795.     while(TRUE)
  1796.         {
  1797.         printf("Enter Station's CTCSS TONE            _______");
  1798.         backup(6);
  1799.         p1 = buf;
  1800.          p2 = reptemp.tone;
  1801.         gets(buf);
  1802.         if(strlen(buf) <= 7 && strlen(buf) > 0) break;
  1803.         }
  1804.     while(*p1 != 0)
  1805.         {
  1806.         if(isalpha(*p1) != 0)
  1807.             *p2++ = toupper(*p1++);
  1808.         else
  1809.             *p2++ = *p1++; 
  1810.         }
  1811.     }
  1812. }
  1813.  
  1814. while(TRUE)
  1815.     {
  1816.     printf("Enter Station's Call Letters          ________");
  1817.     backup(7);
  1818.     p1 = buf;
  1819.     if(num == 4)
  1820.         p2 = gentemp.call;
  1821.     if(num == 9)
  1822.         p2 = reptemp.call;
  1823.     gets(buf);
  1824.     if(strlen(buf) <= 8 && strlen(buf) > 0) break;
  1825.     }
  1826.     while(*p1 != 0)
  1827.         {
  1828.         if(isalpha(*p1) != 0)
  1829.             *p2++ = toupper(*p1++);
  1830.         else
  1831.             *p2++ = *p1++; 
  1832.         }
  1833.  
  1834. while(TRUE)
  1835.     {
  1836. printf("Enter Station's Location       __________________________________");
  1837.     backup(33);
  1838.     p1 = buf;
  1839.     if(num == 4)
  1840.         p2 = gentemp.loc;
  1841.     if(num == 9)
  1842.         p2 = reptemp.loc;
  1843.     gets(buf);
  1844.     if(strlen(buf) <= 34 && strlen(buf) > 0) break;
  1845.     }
  1846.     while(*p1 != 0)
  1847.         *p2++ = toupper(*p1++);
  1848.         *p2 = 0; 
  1849. }       /*end of input_data*/
  1850.  
  1851. void remove_record(int del , int cnt , int num)
  1852. {
  1853. int i,j,len,dest;
  1854. dest = (del - 1);
  1855. if(num < 6)
  1856.     {
  1857.     len = sizeof(struct general);
  1858.     ptg1 = &g[dest];
  1859.     ptg2 = &g[del];
  1860.     memmove(ptg1,ptg2,((cnt + 2) - del)*(len));
  1861.     }
  1862. if(num > 6)
  1863.     {
  1864.     len = sizeof(struct repeater);
  1865.     ptr1 = &r[dest];
  1866.     ptr2 = &r[del];
  1867.     memmove(ptr1,ptr2,((cnt + 2) - del)*(len));
  1868.     }
  1869. reindex(cnt,num,0);
  1870. }       /*end of remove_record*/
  1871.  
  1872. void reindex(int cnt , int num , int j)
  1873. {
  1874. int i;
  1875. for(i = 0;i <= (cnt + j); ++i)
  1876.     {
  1877.     if(num < 6)
  1878.         sprintf(g[i].rec,"%d",(i + 1));
  1879.     if(num >= 6)
  1880.         sprintf(r[i].rec,"%d",(i + 1));
  1881.     }
  1882. }       /*end of reindex*/
  1883.  
  1884. void viewfile(int cnt , int num)
  1885. {
  1886. int i;
  1887. char buff[12],ch;
  1888.  
  1889. clrscr();
  1890. if( num < 6)
  1891.     {
  1892. printf("MEM     Frequency   Mode   Call\t        Location & Comments\n\n");
  1893.     }
  1894. else
  1895.     {
  1896. printf("MEM    Frequency  Mode   CTCSS    Call        Location & Comments\n");
  1897.     }
  1898. for(i = 0;i <= cnt; ++i)
  1899. {
  1900. if(num < 6)
  1901.     {
  1902.     convert(buff,g[i].freq);
  1903.     printf("%-3s   %10s    %-3s    %-8s     %-34s\n",g[i].rec,buff,
  1904.     g[i].mode,g[i].call,g[i].loc);
  1905.     }
  1906. else                 
  1907.     {    
  1908.     convert(buff,r[i].afreq);
  1909.     printf("%-3s A %10s  %-3s   %7s   %-8s %-34s\n",r[i].rec,buff,
  1910.     r[i].mode,r[i].tone,r[i].call,r[i].loc);
  1911.     convert(buff,r[i].bfreq);
  1912.     printf("    B %10s  %-3s   %7s   %-8s %-34s\n",buff,
  1913.     r[i].mode,r[i].tone,r[i].call,r[i].loc);
  1914.     }
  1915. if(num < 6)
  1916.     {
  1917.     if(((i + 1) % 20) == 0 && (i > 0) && (i < cnt))
  1918.         {    
  1919.         if((num == 2) || (num == 5))
  1920.             {
  1921.             gotoxy(14,24);
  1922.         printf("Press ESC to stop paging or any other key for next page --- ");
  1923.             if((ch = _getch()) == ESC)
  1924.                 break;
  1925.             }
  1926.         else
  1927.             press_enter(91,24);
  1928. clrscr();
  1929. printf("MEM     Frequency   Mode   Call\t        Location & Comments\n\n");
  1930.         }
  1931.     }
  1932. else
  1933.     {
  1934.     if(((i + 1) % 10) == 0 && (i > 0) && (i < cnt))
  1935.         {    
  1936.         if((num == 7) || (num == 10))
  1937.             {
  1938.             gotoxy(14,24);
  1939.         printf("Press ESC to stop paging or any other key for next page --- ");
  1940.             if((ch = _getch()) == ESC)
  1941.                 break;
  1942.             }
  1943.         else
  1944.             press_enter(91,24);
  1945. clrscr();
  1946. printf("MEM    Frequency  Mode   CTCSS    Call        Location & Comments\n");
  1947.         }
  1948.     }
  1949. }
  1950. if(ch != ESC)
  1951.     press_enter(90,24);
  1952. }       /*end of viewfile*/
  1953.  
  1954. void press_enter(int x, int y)
  1955. {
  1956. if(x == 90)
  1957.     {
  1958.     gotoxy(0,y);
  1959.     printf("\t\t      End of file     Press ENTER to continue --- ");
  1960.     }
  1961. else
  1962. if(x == 91)
  1963.     {
  1964.     gotoxy(0,y);
  1965.     printf("\t\t     Press ENTER to continue to the next page --- ");
  1966.     }
  1967. else
  1968.     {
  1969.     gotoxy(x,y);
  1970.     printf("Press ENTER to continue --- ");
  1971.     }
  1972. while(_getch() != '\r')
  1973.     gotoxy(61,y);
  1974. }    /*end of press_enter*/
  1975.  
  1976. char *convert(char *buff , char *freq)
  1977. {
  1978. int i,l;
  1979. char first[10];
  1980. char second[12];
  1981.  
  1982.     memset(first,0,10);
  1983.     memset(second,0,12);
  1984.     memcpy(first,freq,strlen(freq));
  1985.     l = strlen(first);
  1986.     second[10] = first[l];
  1987.     second[9] = first[l - 1];
  1988.     second[8] = first[l - 2];
  1989.     second[7] = '.';
  1990.     second[6] = first[l - 3];
  1991.     second[5] = first[l - 4];
  1992.     second[4] = first[l - 5];
  1993.     if(l > 5) 
  1994.     second[3] = ',';
  1995.     else second[3] = ' ';
  1996.     if(l >= 6) 
  1997.     second[2] = first[l - 6];
  1998.     else second[2] = ' ';
  1999.     if(l >= 7) 
  2000.     second[1] = first[l - 7];
  2001.     else second[1] = ' ';
  2002.     if(l >= 8) 
  2003.     second[0] = first[l - 8];
  2004.     else second[0] = ' ';
  2005.     for(i = 0;i <= strlen(second);i++)
  2006.         *(buff + i) = second[i];
  2007.     return(buff);
  2008. }    /*end of convert*/
  2009.  
  2010. void recall(int num)
  2011. {
  2012. int k;
  2013. char fbuf[15],mbuf[8],freq[5] = "freq ",mode[5] = "mode ";
  2014. char *loq,*hiq,*p1,*p2,buff[5];
  2015. char tonebuf[18],loqtone[9] = "tone loq ",hiqtone[9] = "tone hiq ";
  2016.  
  2017. clrscr();
  2018. gotoxy(15,8);
  2019. printf("If you know the MEM number of the station you want");
  2020. gotoxy(34,10);
  2021. printf("Enter it now,");
  2022. gotoxy(19,12);
  2023. printf("or Enter a 0 to view the station list --- ");
  2024. gotoxy(15,14);
  2025. printf("Examine the contents of the Data File and take note\n");
  2026. gotoxy(15,16);
  2027. printf("of the MEM number of the station you wish to recall.");
  2028. gotoxy(25,18);
  2029. printf("Enter it when directed to do so.");
  2030. gotoxy(61,12);
  2031. scanf("%d",&k);
  2032. clrscr();
  2033.  
  2034. if(k == 0)
  2035.     {
  2036.     examine_files(num);
  2037.     gotoxy(0,24);
  2038.     CLREOL;
  2039.     gotoxy(23,24);
  2040.     printf("Enter the selected MEM number --- ");
  2041.     scanf("%i",&k);
  2042.     k--;
  2043.     }
  2044. else
  2045.     {
  2046.     loadfile(num);
  2047.     k--;
  2048.     }
  2049.  
  2050. #undef tolower 
  2051. if(num < 6)
  2052.     {
  2053.     do_it("aclr");
  2054.     do_it("gen");
  2055.     do_it("vfo a");
  2056.     
  2057.     memcpy(fbuf,freq,5);
  2058.     memcpy(fbuf + 5,g[k].freq,strlen(g[k].freq) + 1);
  2059.     do_it(fbuf);
  2060.  
  2061.     p1 = g[k].mode;
  2062.     p2 = buff;
  2063.     while(*p1 != 0)
  2064.         *p2++ = tolower(*p1++);
  2065.         *p2 = 0;
  2066.     memcpy(mbuf,mode,5);
  2067.     memcpy(mbuf + 5,buff,strlen(buff) + 1);
  2068.     do_it(mbuf);
  2069.     }
  2070. else
  2071.     {
  2072.     do_it("aclr");
  2073.     do_it("ham");
  2074.  
  2075.     do_it("vfo b");
  2076.     memcpy(fbuf,freq,5);
  2077.     memcpy(fbuf + 5,r[k].bfreq,strlen(r[k].bfreq) + 1);
  2078.     do_it(fbuf);
  2079.  
  2080.     p1 = r[k].mode;
  2081.     p2 = buff;
  2082.     while(*p1 != 0)
  2083.         *p2++ = tolower(*p1++);
  2084.         *p2 = 0;
  2085.     memcpy(mbuf,mode,5);
  2086.     memcpy(mbuf + 5,buff,strlen(buff) + 1);
  2087.     do_it(mbuf);
  2088.  
  2089.     if(r[k].tone[0] == 'C')
  2090.         {
  2091.         hiq = r[k].tone;
  2092.         while(isdigit(*hiq) == 0) hiq++;
  2093.         memcpy(tonebuf,hiqtone,9);
  2094.         memcpy(tonebuf + 9,hiq,strlen(r[k].tone) - 1);
  2095.         do_it(tonebuf);
  2096.         }    
  2097.     else    
  2098.         {
  2099.         loq = r[k].tone;
  2100.         while(isdigit(*loq) == 0) loq++;
  2101.         memcpy(tonebuf,loqtone,9);
  2102.         memcpy(tonebuf + 9,loq,strlen(r[k].tone) + 1);
  2103.         do_it(tonebuf);
  2104.         }    
  2105.     do_it("vfo a");
  2106.     memcpy(fbuf,freq,5);
  2107.     memcpy(fbuf + 5,r[k].afreq,strlen(r[k].afreq) + 1);
  2108.     do_it(fbuf);
  2109.  
  2110.     p1 = r[k].mode;
  2111.     p2 = buff;
  2112.     while(*p1 != 0)
  2113.         *p2++ = tolower(*p1++);
  2114.         *p2 = 0;
  2115.     memcpy(mbuf,mode,5);
  2116.     memcpy(mbuf + 5,buff,strlen(buff) + 1);
  2117.     do_it(mbuf);
  2118.  
  2119.     if(r[k].tone[0] == 'C')
  2120.         {
  2121.         hiq = r[k].tone;
  2122.         while(isdigit(*hiq) == 0) hiq++;
  2123.         memcpy(tonebuf,hiqtone,9);
  2124.         memcpy(tonebuf + 9,hiq,strlen(r[k].tone) - 1);
  2125.         do_it(tonebuf);
  2126.         }
  2127.     else
  2128.         {
  2129.         loq = r[k].tone;
  2130.         while(isdigit(*loq) == 0) loq++;
  2131.         memcpy(tonebuf,loqtone,9);
  2132.         memcpy(tonebuf + 9,loq,strlen(r[k].tone) + 1);
  2133.         do_it(tonebuf);
  2134.         }
  2135.     do_it("split on");
  2136.     }
  2137. }    /*end of recall*/
  2138.  
  2139. void do_it(char *func)
  2140. {
  2141. int cnt;
  2142.     match(func,parse(func));
  2143.     sendcmd();
  2144.     for(cnt = 0;cnt <= 18000;cnt++);
  2145. }    /*end of do_it*/
  2146.  
  2147. char *hertz(char *buffer, int k)
  2148. {
  2149. char freq[12];
  2150. int j,temp[3];
  2151.  
  2152. temp[3] = status[bytcnt - k--];
  2153. temp[2] = status[bytcnt - k--];
  2154. temp[1] = status[bytcnt - k--];
  2155. temp[0] = status[bytcnt - k];
  2156.  
  2157. freq[8] = 0;
  2158. freq[7] = temp[3];
  2159. freq[7] = (freq[7] & 0xf) + 48;
  2160. freq[6] = (temp[3] >> 4) + 48;
  2161. freq[5] = temp[2];
  2162. freq[5] = (freq[5] & 0xf) + 48;
  2163. freq[4] = (temp[2] >>4) + 48;
  2164. freq[3] = temp[1];
  2165. freq[3] = (freq[3] & 0xf) + 48;
  2166. freq[2] = (temp[1] >> 4) +48;
  2167. freq[1] = temp[0];
  2168. freq[1] = (freq[1] & 0xf) + 48;
  2169. freq[0] = (temp[0] >> 4) + 48;
  2170.  
  2171. if((freq[0] == '0') && (freq[1] == '0') && (freq[2] == '0'))
  2172.     freq[0] = freq[1] = freq[2] =  ' ';
  2173. if((freq[0] == '0') && (freq[1] == '0'))
  2174.     freq[0] = freq[1] = ' ';
  2175. if(freq[0] == '0')
  2176.     freq[0] = ' ';
  2177. for(j = 0;j <= strlen(freq);j++)
  2178.     *(buffer + j) = freq[j];
  2179. return(buffer);
  2180. }       /* end of hertz */
  2181.  
  2182. void vfo_mode(int m)
  2183. {
  2184.     int temp;
  2185.     char mbuff[5],*p1,*p2;
  2186.     p1 = mbuff;
  2187.     temp = status[bytcnt - m];
  2188.     switch(temp & 0x7)
  2189.         {
  2190.         case(0) : p1 = "LSB"; break;
  2191.         case(1) : p1 = "USB"; break;
  2192.         case(2) : p1 = "CW"; break;
  2193.         case(3) : p1 = "AM"; break;
  2194.         case(4) : p1 = "FM"; break;
  2195.         case(5) : p1 = "FSK"; break;
  2196.         }
  2197. if(m == 7)
  2198.     p2 = gentemp.mode;
  2199. else
  2200.     if(m == 20)
  2201.         p2 = reptemp.mode;
  2202.     while(*p1 != 0)
  2203.         *p2++ = *p1++;
  2204.         *p2 = 0;
  2205. } /*end of vfo_mode*/
  2206.  
  2207. void get_data(int num)
  2208. {
  2209. char buf[42],*p1,*p2;
  2210. #undef toupper
  2211. if(num == 1)
  2212.     memset(&gentemp,0,sizeof(struct general) + 1);
  2213. if(num == 6)
  2214.     memset(&reptemp,0,sizeof(struct repeater) + 1);
  2215. clrscr();
  2216. printf("\n\n\n");
  2217. if(num == 1)
  2218. {
  2219.     hertz(gentemp.freq,5);
  2220.     vfo_mode(7);
  2221. }
  2222. if(num == 6)
  2223. {
  2224. hertz(reptemp.afreq,18);
  2225. vfo_mode(20);
  2226. hertz(reptemp.bfreq,24);
  2227. pl_tone(25);
  2228. }
  2229. while(TRUE)
  2230.     {
  2231.     printf("Enter Station's Call Letters   ________");
  2232.     backup(7);
  2233.     p1 = buf;
  2234.     if(num == 1)
  2235.         p2 = gentemp.call;
  2236.     if(num == 6)
  2237.         p2 = reptemp.call;
  2238.     gets(buf);
  2239.     if(strlen(buf) <= 8 && strlen(buf) > 0) break;
  2240.     }
  2241.     while(*p1 != 0)
  2242.         {
  2243.         if(isalpha(*p1) != 0)
  2244.             *p2++ = toupper(*p1++);
  2245.         else
  2246.             *p2++ = *p1++; 
  2247.         }
  2248. while(TRUE)
  2249.     {
  2250. printf("Enter Station's Location       __________________________________");
  2251.     backup(33);
  2252.     p1 = buf;
  2253.     if(num == 1)
  2254.         p2 = gentemp.loc;
  2255.     if(num == 6)
  2256.         p2 = reptemp.loc;
  2257.     gets(buf);
  2258.     if(strlen(buf) <= 34 && strlen(buf) > 0) break;
  2259.     }
  2260.     while(*p1 != 0)
  2261.         *p2++ = toupper(*p1++);
  2262.         *p2 = 0; 
  2263. }       /*end of get_data*/
  2264.  
  2265. void pl_tone(int b)
  2266. {
  2267. int tone;
  2268. char tbuf[9],*p1,*p2;
  2269. p1 = tbuf;
  2270. tone = (status[bytcnt - b] & 0x3f);
  2271. switch(tone)
  2272.     {
  2273.     case(0) : p1 = "  67.0"; break;
  2274.     case(1) : p1 = "  71.9"; break;
  2275.     case(2) : p1 = "  77.0"; break;
  2276.     case(3) : p1 = "  82.5"; break;
  2277.     case(4) : p1 = "  88.5"; break;
  2278.     case(5) : p1 = "  94.8"; break;
  2279.     case(6) : p1 = " 100.0"; break;
  2280.     case(7) : p1 = " 103.5"; break;
  2281.     case(8) : p1 = " 107.2"; break;
  2282.     case(9) : p1 = " 110.9"; break;
  2283.     case(10) : p1 = " 114.8"; break;
  2284.     case(11) : p1 = " 118.8"; break;
  2285.     case(12) : p1 = " 123.0"; break;
  2286.     case(13) : p1 = " 127.3"; break;
  2287.     case(14) : p1 = " 131.8"; break;
  2288.     case(15) : p1 = " 136.5"; break;
  2289.     case(16) : p1 = " 141.3"; break;
  2290.     case(17) : p1 = " 146.2"; break;
  2291.     case(18) : p1 = " 151.4"; break;
  2292.     case(19) : p1 = " 156.7"; break;
  2293.     case(20) : p1 = " 162.2"; break;
  2294.     case(21) : p1 = " 167.9"; break;
  2295.     case(22) : p1 = " 173.8"; break;
  2296.     case(23) : p1 = " 179.9"; break;
  2297.     case(24) : p1 = " 186.2"; break;
  2298.     case(25) : p1 = " 192.8"; break;
  2299.     case(26) : p1 = " 203.5"; break;
  2300.     case(27) : p1 = " 210.7"; break;
  2301.     case(28) : p1 = " 218.1"; break;
  2302.     case(29) : p1 = " 225.7"; break;
  2303.     case(30) : p1 = " 233.6"; break;
  2304.     case(31) : p1 = " 241.8"; break;
  2305.     case(32) : p1 = " 250.3"; break;
  2306.     case(33) : p1 = "C 67.0"; break;
  2307.     case(34) : p1 = "C 71.9"; break;
  2308.     case(35) : p1 = "C 74.7"; break;
  2309.     case(36) : p1 = "C 77.0"; break;
  2310.     case(37) : p1 = "C 79.7"; break;
  2311.     case(38) : p1 = "C 82.5"; break;
  2312.     case(39) : p1 = "C 85.4"; break;
  2313.     case(40) : p1 = "C 88.5"; break;
  2314.     case(41) : p1 = "C 91.5"; break;
  2315.     }
  2316. p2 = reptemp.tone;
  2317. while(*p1 != 0)
  2318.     *p2++ = *p1++;
  2319.     *p2 = 0;
  2320. }       /* end of pl_tone */
  2321.  
  2322. void edit_control(void)
  2323. {
  2324. char option;
  2325.  
  2326. clrscr();
  2327. gotoxy(0,3);
  2328. printf("\t           EDIT  operates independently from the FT-767GX  CAT\n");
  2329. printf("\t      function of this program.  The FT-767GX need not be\n"); 
  2330. printf("\t      turned  on during its use.  EDIT allows the  direct\n"); 
  2331. printf("\t      viewing,  insertion,  and/or  deletion  of  station\n"); 
  2332. printf("\t      records  into/from the disk memory files.  However,\n"); 
  2333. printf("\t      It will  only permit one to change a station's call\n"); 
  2334. printf("\t      letters and/or location and comments about it.\n\n");
  2335. printf("\t      When added to the files, stations are automatically\n"); 
  2336. printf("\t      placed   sorted  in  frequency   order.  Therefore,\n"); 
  2337. printf("\t      editing the  frequencies can not be permitted.\n\n");
  2338. printf("\t      To change a station's frequency, mode or CTCSS tone\n"); 
  2339. printf("\t      remove  the station's record from the file and then\n"); 
  2340. printf("\t      add  it  back  into  the file  with  the  corrected\n"); 
  2341. printf("\t      information.\n");
  2342. press_enter(33,24);
  2343.  
  2344.     clrscr();
  2345.     printf("\t\t\t       Edit disk memories\n\n");
  2346.     printf("\t\t\t General Coverage Reception and\n");
  2347.     printf("\t\t\t Amateur Band Simplex operation\n\n");
  2348.     printf("\t   1  - View the General Stations file\n");
  2349.     printf("\t   2  - Edit a General Station Record\n");
  2350.     printf("\t   3  - Add Stations to General Coverage disk memory by hand\n");
  2351.     printf("\t   4  - Remove Stations from General Coverage disk memory\n");
  2352.     printf("\n\t\t\t Amateur Band Split Frequency\n");
  2353.     printf("\t\t\t    and Repeater Operation\n\n");
  2354.     printf("\t   5  - View the Amateur Band Repeater Stations file\n");
  2355.     printf("\t   6  - Edit an Amateur Band Repeater Station Record\n");
  2356.     printf("\t   7  - Add Stations to Amateur Repeater disk memory by hand\n");
  2357.     printf("\t   8  - Remove Stations from Amateur Repeater disk memory\n");
  2358.     printf("\n\t   9  - To go to main program\n\n");
  2359.     printf("\t        Enter selection --- ");
  2360.     do
  2361.         {
  2362.         gotoxy(45,21);
  2363.         option = _getch();
  2364.         } while((option < '1') || (option > '9'));
  2365. fflush(stdin);
  2366. edit_selection(option);
  2367. }    /*end of edit_control*/
  2368.  
  2369. char edit_selection(char opt)
  2370. {
  2371. char ch;
  2372. switch(opt)
  2373.         {
  2374.         case '1': examine_files(3); break;
  2375.         case '2': edit_records(2); break;
  2376.         case '3': add_station(4); break;
  2377.         case '4': delete_station(5); break;
  2378.         case '5': examine_files(8); break;
  2379.         case '6': edit_records(7); break;
  2380.         case '7': add_station(9); break;
  2381.         case '8': delete_station(10); break;
  2382.         default: return(0);
  2383.         }
  2384. do
  2385. {
  2386.     CLRSCR;
  2387.     gotoxy(0,10);
  2388.     printf("\n\t\t\t   1  - Run CAT program\n");
  2389.     printf("\t\t\t   2  - Return to DOS\n");
  2390.     printf("\n\t\t\t\tEnter selection --- ");
  2391.     ch = _getch();
  2392.     if(ch == '2') exit(0);
  2393.     else
  2394.     if(ch == '1') ;
  2395. }
  2396. while((ch > '2') || (ch < '1'));
  2397. }    /*end of edit_selection*/
  2398.  
  2399. void edit_records(int num)
  2400. {
  2401.     int record_cnt,ed_rec;
  2402.  
  2403. for(;;)
  2404. {
  2405.     record_cnt = loadfile(num);
  2406.     if(record_cnt == -3) break;
  2407.  
  2408. do
  2409. {
  2410.     viewfile(record_cnt,num);
  2411.     gotoxy(0,24);
  2412.     CLREOL;
  2413.     gotoxy(13,24);
  2414.     printf("Enter the MEM number of the station record to be edited --- ");
  2415.     scanf("%d",&ed_rec);
  2416.     ed_rec--;
  2417. }
  2418. while((ed_rec < 1) || (ed_rec > record_cnt));
  2419.  
  2420. if((ed_rec == 1) && (record_cnt == 0))
  2421.     {
  2422.     if(num == 2)
  2423.         system("del general.dat");
  2424.     if(num == 7)
  2425.         system("del repeater.dat");
  2426.     }
  2427. else
  2428.     {
  2429.         edit_station_record(ed_rec,num);
  2430.         if(num == 2)
  2431.             savedata(record_cnt,num);
  2432.         if(num == 7)
  2433.             savedata(record_cnt,num);
  2434.     }    
  2435.     clrscr();
  2436.     gotoxy(0,6);
  2437. if(num == 2)
  2438.     printf("The station's call letters are now %s\n",g[ed_rec].call);
  2439. if(num == 7)
  2440.     printf("The station's call letters are now %s\n",r[ed_rec].call);
  2441. if(num == 2)
  2442.     printf("The station's location and/or comment is now %s\n",g[ed_rec].loc);
  2443. if(num == 7)
  2444.     printf("The station's location and/or comment is now %s\n",r[ed_rec].loc);
  2445.  
  2446.     gotoxy(0,12);
  2447.     printf("\n\n\t\tEdit another station record? y or n --- ");
  2448.     if(getreply() == 1) break;
  2449.     }
  2450. }    /*end of edit_records*/
  2451.  
  2452. void edit_station_record(int rec, int num)
  2453. {
  2454. int i;
  2455. char buf[42],*p1,*p2;
  2456. #undef toupper 
  2457. clrscr();
  2458. printf("\n\n\n");
  2459. if(num == 2)
  2460.     printf("The call letters are now %s\n",g[rec].call);
  2461. if(num == 7)
  2462.     printf("The call letters are now %s\n",r[rec].call);
  2463. printf("Do you wish to edit the call letters? y or n --- ");
  2464. if(getreply() == 1) putchar('\n');
  2465. else
  2466.     {
  2467.         putchar('\n');
  2468.         fflush(stdin);
  2469.         while(TRUE)
  2470.         {
  2471.         printf("Enter Station's Call Letters   ________");
  2472.         backup(7);
  2473.         p1 = buf;
  2474.         if(num == 2)
  2475.             p2 = g[rec].call;
  2476.         if(num == 7)
  2477.             p2 = r[rec].call;
  2478.         for(i = 0;i <= 8;i++)
  2479.             *p2++ = 0;
  2480.         if(num == 2)
  2481.             p2 = g[rec].call;
  2482.         if(num == 7)
  2483.             p2 = r[rec].call;
  2484.         gets(buf);
  2485.         if(strlen(buf) <= 8 && strlen(buf) > 0) break;
  2486.         }
  2487.         while(*p1 != 0)
  2488.             {
  2489.             if(isalpha(*p1) != 0)
  2490.                 *p2++ = toupper(*p1++);
  2491.             else
  2492.                 *p2++ = *p1++; 
  2493.             }
  2494.     }
  2495. printf("\n\n\n");
  2496. if(num == 2)
  2497.     printf("The location and/or comment is now %s\n",g[rec].loc);
  2498. if(num == 7)
  2499.     printf("The location and/or comment is now %s\n",r[rec].loc);
  2500. printf("Do you wish to edit the location and/or comment? y or n --- ");
  2501. if(getreply() == 1) putchar('\n');
  2502. else
  2503.     {
  2504.     putchar('\n');
  2505.     fflush(stdin);
  2506.     while(TRUE)
  2507.     {
  2508. printf("Enter Information       __________________________________");
  2509.         backup(33);
  2510.         p1 = buf;
  2511.         if(num == 2)
  2512.             p2 = g[rec].loc;
  2513.         if(num == 7)
  2514.             p2 = r[rec].loc;
  2515.         for(i = 0;i <= 34;i++)
  2516.                 *p2 = 0;
  2517.         if(num == 2)
  2518.             p2 = g[rec].loc;
  2519.         if(num == 7)
  2520.             p2 = r[rec].loc;
  2521.         gets(buf);
  2522.         if(strlen(buf) <= 34 && strlen(buf) > 0) break;
  2523.         }
  2524.         while(*p1 != 0)
  2525.             *p2++ = toupper(*p1++);
  2526.             *p2 = 0;
  2527.     }
  2528. }    /*end of edit_station_record*/
  2529.